<template>
  <a-modal
    :title="title"
    :width="1250"
    :visible="visible"
    v-if="visible"
    @cancel="handleCancel"
    :cancelText="$t('systemManagement.close')"
    wrapClassName="ant-modal-cust-warp"
    style="top:5%;height: 100%;overflow-y: hidden">
    <template slot="footer">
      <a-button key="back" @click="handleCancel">{{$t('inPrint.cancel')}}</a-button>
    </template>
    <!-- table区域-begin -->
    <a-table
      bordered
      ref="table"
      size="middle"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange">
    </a-table>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <bill-detail ref="billDetail"></bill-detail> -->
  </a-modal>
</template>
<script>
  import BillDetail from '../../bill/dialog/BillDetail'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import {findBillDetailByNumber, findFinancialDetailByNumber} from '@/api/api'
  import {directScheduleRemark} from '@/lang/category';
  import {getLanCode} from '@/lang';
  import {getAction} from '@/api/manage'
  export default {
    name: "MaterialInOutList",
    mixins:[JeecgListMixin],
    components: {
      BillDetail,
      JEllipsis
    },
    data () {
      return {
        title:this.$t('setailManagement.operation'),
        visible: false,
        disableMixinCreated: false,
        toFromType: '',
        // 查询条件
        queryParam: {},
        tabKey: "1",
        columns: [],
        // 表头
        orderNumberColumns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'5%', align: 'center',
            customRender: (t,r,index) => parseInt(index)+1
          },
          { title: this.$t('inPrint.date'), dataIndex: 'operTime', width: 100},
          { title: this.$t('setailManagement.documentNo'), dataIndex: 'number', width: 100},
          { title: this.$t('reportQuery.supplier'), dataIndex: 'supplier', width: 100},
          { title: this.$t('basicInformation.warehouseName'), dataIndex: 'depotName', width: 80},
          { title: this.$t('reportQuery.goodsName'), dataIndex: 'materialName', width: 200},
          { title: this.$t('reportQuery.category'), dataIndex: 'categoryName' },
          { title: this.$t('reportQuery.quantity'), dataIndex: 'operNumber', width: 80}
        ],
        quotationNumberColumns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'5%', align: 'center',
            customRender: (t,r,index) => parseInt(index)+1
          },
          { title: this.$t('inPrint.date'), dataIndex: 'operTime', width: 100},
          { title: this.$t('setailManagement.documentNo'), dataIndex: 'number', width: 100},
          { title: this.$t('reportQuery.supplier'), dataIndex: 'supplier', width: 100},
          { title: this.$t('reportQuery.goodsName'), dataIndex: 'materialName', width: 200},
          { title: this.$t('reportQuery.category'), dataIndex: 'categoryName' },
          { title: this.$t('reportQuery.quantity'), dataIndex: 'operNumber', width: 80}
        ],
        exchangeNumberColumns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'5%', align: 'center',
            customRender: (t,r,index) => parseInt(index)+1
          },
          { title: this.$t('inPrint.date'), dataIndex: 'operTime', width: 100},
          {title: this.$t('setailManagement.documentNo'), dataIndex: 'number', width: 100},
          { title: this.$t('reportQuery.supplier'), dataIndex: 'supplier', width: 100},
          { title: this.$t('reportQuery.goodsName'), dataIndex: 'materialName', width: 200},
          { title: this.$t('reportQuery.category'), dataIndex: 'categoryName' },
          { title: this.$t('reportQuery.quantity'), dataIndex: 'operNumber', width: 80},
          { title: this.$t('basicInformation.type'), dataIndex: 'newType', width: 100,customRender:(t,r)=>{
            if(getLanCode() === 'en'){
              return directScheduleRemark[t] || t
            }
            return t
          }},
          { title: this.$t('reportQuery.remarks'), dataIndex: 'newRemark', width: 80,customRender:(t,r)=>{
            if(getLanCode() === 'en'){
              return directScheduleRemark[t] || t
            }
            return t
          }}
        ],
        breakNumberColumns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'5%', align: 'center',
            customRender: (t,r,index) => parseInt(index)+1
          },
          { title: this.$t('inPrint.date'), dataIndex: 'operTime', width: 100},
          {title: this.$t('setailManagement.documentNo'), dataIndex: 'number', width: 100},
          { title: this.$t('reportQuery.supplier'), dataIndex: 'supplier', width: 100},
          { title: this.$t('reportQuery.goodsName'), dataIndex: 'materialName', width: 200},
          { title: this.$t('reportQuery.category'), dataIndex: 'categoryName' },
          { title: this.$t('reportQuery.quantity'), dataIndex: 'operNumber', width: 80},
          { title: this.$t('basicInformation.type'), dataIndex: 'newType', width: 100,customRender:(t,r)=>{
            if(getLanCode() === 'en'){
              return directScheduleRemark[t] || t
            }
            return t
          }},

          { title: this.$t('reportQuery.remarks'), dataIndex: 'newRemark', width: 80,customRender:(t,r)=>{
            if(getLanCode() === 'en'){
              return directScheduleRemark[t] || t
            }
            return t
          }}
        ],
        finishNumberColumns: [
          {
            title: this.$t('defaultTranslate.lineNumber'),dataIndex: 'rowIndex',width:'5%', align: 'center',
            customRender: (t,r,index) => parseInt(index)+1
          },
          { title: this.$t('inPrint.date'), dataIndex: 'operTime', width: 100},
          {title: this.$t('setailManagement.documentNo'), dataIndex: 'number', width: 100},
          { title: this.$t('basicInformation.warehouseName'), dataIndex: 'depotName', width: 80},
          { title: this.$t('reportQuery.goodsName'), dataIndex: 'materialName', width: 200},
          { title: this.$t('reportQuery.category'), dataIndex: 'categoryName' },
          { title: this.$t('reportQuery.quantity'), dataIndex: 'operNumber', width: 80},
          { title: this.$t('manuManagement.breakageType'), dataIndex: 'custom11', width: 80,customRender: (t,r,index) => {
            if(+t === 0){
              return this.$t('manuManagement.breakageTypeNormal')
            }else if(+t === 1){
              return this.$t('manuManagement.breakageTypeBreaked')
            }else if(+t === 2){
              return this.$t('manuManagement.breakageTypeExchanged')
            }
          }},
          { title: this.$t('manuManagement.breakageNum'), dataIndex: 'differNumber', width: 80},
        ],
        labelCol: {
          xs: { span: 1 },
          sm: { span: 2 },
        },
        wrapperCol: {
          xs: { span: 10 },
          sm: { span: 16 },
        },
        url: {
          list: "/depotHead/trackingDetailList"
        }
      }
    },
    created() {
    },
    methods: {
      getQueryParams() {
        let param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.currentPage = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return param;
      },
      show(record,title) {
        this.model = Object.assign({}, record);
        this.visible = true;
        let param = {}
        switch (title) {
          case this.$t('reportQuery.orderCount'):
            param = {
              linkNumber: record.number,
              type: '其它',
              subType: '厂家直发',
              orderType: ''
            }
            this.columns = this.orderNumberColumns
            break
          case this.$t('reportQuery.purchaseOrderNumber'):
            param = {
              linkNumber: record.number,
              type: '其它',
              subType: '下达采购',
              orderType: ''
            }
            this.columns = this.orderNumberColumns
            break
          case this.$t('reportQuery.quotationNumber'):
            param = {
              linkNumber: record.number,
              type: '其它',
              subType: '直发厂家报价',
              orderType: ''
            }
            this.columns = this.quotationNumberColumns
            break
          case this.$t('reportQuery.exchangeNumber'):
            param = {
              linkNumber: record.number,
              type: '其它',
              subType: '直发销售退货',
              orderType: 2
            }
            this.columns = this.exchangeNumberColumns
            break
          case this.$t('reportQuery.breakNumber'):
            param = {
              linkNumber: record.number,
              type: '其它',
              subType: '直发销售退货',
              orderType: 1
            }
            this.columns = this.breakNumberColumns
            break
          case this.$t('reportQuery.finishNumber'):
            param = {
              linkNumber: record.number,
              type: '到货',
              subType: '厂家到货',
              orderType: ''
            }
            this.columns = this.finishNumberColumns
            break
          case this.$t('reportQuery.PurchaseAcceptanceNumber'):
            param = {
              linkNumber: record.number,
              type: '其它',
              subType: '收费确认',
              orderType: ''
            }
            this.columns = this.finishNumberColumns
            break
          }
        this.title = title +' - ' + this.$t('reportQuery.detail');
        this.queryParam = param
        this.loadData(1)
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      loadData (arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      // var params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, this.queryParam).then(res => {
        if (res.code === 200) {
          this.dataSource = res.data
          
          // this.ipagination.total = res.data.total
        }
        if (res.code === 510) {
          this.$message.warning(res.data)
        }
          this.loading = false
        })
      },
      myHandleDetail(record) {
        let that = this
        this.toFromType = record.fromType
        findBillDetailByNumber({ number: record.number }).then((res) => {
          if (res && res.code === 200) {
            that.$refs.billDetail.show(res.data, record.type);
            that.$refs.billDetail.title=this.$t('reportQuery.details');
          }
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>